﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TiTi.tea.Comm;
using TiTi.tea.DAL;
using TiTi.tea.Dto;
using TiTi.tea.Model;

namespace TiTi.tea.BLL
{
    public class MaterialBLL
    {
        private MaterialDAL mateDal = new MaterialDAL();

        /// <summary>
        /// 获取小料
        /// </summary>
        /// <returns></returns>
        public IEnumerable<MaterialDto> GetAll()
        {
            return mateDal.GetAll(o=>o.IsDelete==0&&o.Status==1).Select(o=>new MaterialDto()
            {
                Id = o.Id,
                MatName = o.MatName,
                Price = o.Price,
            });
        }

        /// <summary>
        /// 分页获取
        /// </summary>
        /// <param name="matName"></param>
        /// <param name="pagePara"></param>
        /// <returns></returns>
        public IEnumerable<Material> GetAll(string matName,PagePara pagePara)
        {
            if (string.IsNullOrEmpty(matName)) matName = "";
            var data = mateDal.GetAll(o => o.IsDelete == 0&&o.MatName.Contains(matName));
            return data.SetPage(o => o.Id, pagePara);
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="para"></param>
        /// <returns></returns>
        public bool Update(Material para)
        {
            return mateDal.Update(para);
        }
/// <summary>
/// 添加
/// </summary>
/// <param name="para"></param>
/// <returns></returns>
        public bool Add(Material para)
        {
            para.IsDelete = 0;
            para.Status = 1;
            return mateDal.Add(para);
        }
        /// <summary>
        /// 查询单个
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public Material GetOne(int Id)
        {
            return mateDal.GetOne(o => o.Id == Id);
        }
    }
}
